package com.ruoyi.safe.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.safe.domain.TSpecialZone;
import com.ruoyi.safe.service.ITSpecialZoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 专区Controller
 *
 * @author zmk
 * @date 2025-03-24
 */
@RestController
@RequestMapping("/safe/zone")
public class TSpecialZoneController extends BaseController {
    @Autowired
    private ITSpecialZoneService tSpecialZoneService;

    /**
     * 查询专区列表
     */
    @PreAuthorize("@ss.hasPermi('safe:zone:list')")
    @GetMapping("/list")
    public AjaxResult list(TSpecialZone tSpecialZone) {
        List<TSpecialZone> list = tSpecialZoneService.selectTSpecialZoneList(tSpecialZone);
        return success(list);
    }

    /**
     * 导出专区列表
     */
    @PreAuthorize("@ss.hasPermi('safe:zone:export')")
    @Log(title = "专区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSpecialZone tSpecialZone) {
        List<TSpecialZone> list = tSpecialZoneService.selectTSpecialZoneList(tSpecialZone);
        ExcelUtil<TSpecialZone> util = new ExcelUtil<TSpecialZone>(TSpecialZone.class);
        util.exportExcel(response, list, "专区数据");
    }

    /**
     * 获取专区详细信息
     */
    @PreAuthorize("@ss.hasPermi('safe:zone:query')")
    @GetMapping(value = "/{zoneId}")
    public AjaxResult getInfo(@PathVariable("zoneId") Long zoneId) {
        return success(tSpecialZoneService.selectTSpecialZoneByZoneId(zoneId));
    }

    /**
     * 新增专区
     */
    @PreAuthorize("@ss.hasPermi('safe:zone:add')")
    @Log(title = "专区", businessType = BusinessType.INSERT, logType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSpecialZone tSpecialZone) {
        return toAjax(tSpecialZoneService.insertTSpecialZone(tSpecialZone));
    }

    /**
     * 修改专区
     */
    @PreAuthorize("@ss.hasPermi('safe:zone:edit')")
    @Log(title = "专区", businessType = BusinessType.UPDATE, logType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSpecialZone tSpecialZone) {
        return toAjax(tSpecialZoneService.updateTSpecialZone(tSpecialZone));
    }

    /**
     * 删除专区
     */
    @PreAuthorize("@ss.hasPermi('safe:zone:remove')")
    @Log(title = "专区", businessType = BusinessType.DELETE)
    @DeleteMapping("/{zoneIds}")
    public AjaxResult remove(@PathVariable Long[] zoneIds) {
        return toAjax(tSpecialZoneService.deleteTSpecialZoneByZoneIds(zoneIds));
    }

    @PreAuthorize("@ss.hasPermi('safe:zone:edit')")
    @Log(title = "专区")
    @PutMapping("/updateStatus/{zoneId}/{delFlag}")
    public AjaxResult updateStatus(@PathVariable Integer delFlag, @PathVariable Long zoneId) {
        return toAjax(tSpecialZoneService.updateStatus(delFlag, zoneId));
    }
}
